//////////////////////////////////////////////////////////////////////////////////////////////
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	File			:	"MenuFont.cpp"
//	Authors			:	Jake Castillo,
//	Date:			:	08/06/2013
//	Project			:	Project Aetheryte
//	Purpose			:	Bitmap Font class for the menus of the game.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//////////////////////////////////////////////////////////////////////////////////////////////


#include "MenuFont.h"

#include "../SGD Wrappers/CSGD_TextureManager.h"
#include "../Game Essentials/Game.h"

#include <cassert>


MenuFont::MenuFont(void)
{
}


MenuFont::~MenuFont(void)
{
}

/*virtual*/ void MenuFont::Initialize( const TCHAR* szFilepath, int nWidth,  
									  int nHeight,  int nCols, int nRows, bool OnlyUpper,  TCHAR cFirstChar, unsigned int lang )
{
	// Load the image
	m_nImageID = CSGD_TextureManager::GetInstance()->LoadTexture(szFilepath);

	// Validate
	assert( m_nImageID != -1 && "CBitmapFont::Draw - image was not loaded." );

	m_nCharWidth		= nWidth;
	m_nCharHeight		= nHeight;
	m_nNumCols			= nCols;
	m_nNumRows			= nRows;

	m_bOnlyUppercase	= OnlyUpper;
	m_cFirstChar		= cFirstChar;

	language = lang;

	CreateLookup();
}

void MenuFont::Terminate( void )		
{
	CSGD_TextureManager::GetInstance()->UnloadTexture( m_nImageID );
	m_nImageID = -1;

	for(int i = 0; i < m_nNumRows; i++)
	{
		delete[] LookupTable[i];
	}

	delete[] LookupTable;
}

void MenuFont::CreateLookup()
{
	int arrLookup[6][16];

	if(language == CGame::GetInstance()->English)
	{
		// Hard-coded lookup table
		arrLookup[0][0]		= 15;
		arrLookup[0][1]		= 14;
		arrLookup[0][2]		= 21;
		arrLookup[0][3]		= 38;
		arrLookup[0][4]		= 26;
		arrLookup[0][5]		= 42;
		arrLookup[0][6]		= 52;
		arrLookup[0][7]		= 12;
		arrLookup[0][8]		= 41;
		arrLookup[0][9]		= 41;
		arrLookup[0][10]	= 22;
		arrLookup[0][11]	= 36;
		arrLookup[0][12]	= 15;
		arrLookup[0][13]	= 15;
		arrLookup[0][14]	= 15;
		arrLookup[0][15]	= 25;
						  
		arrLookup[1][0]		= 44;
		arrLookup[1][1]		= 20;
		arrLookup[1][2]		= 33;
		arrLookup[1][3]		= 39;
		arrLookup[1][4]		= 42;
		arrLookup[1][5]		= 40;
		arrLookup[1][6]		= 41;
		arrLookup[1][7]		= 40;
		arrLookup[1][8]		= 37;
		arrLookup[1][9]		= 42;
		arrLookup[1][10]	= 13;
		arrLookup[1][11]	= 13;
		arrLookup[1][12]	= 31;
		arrLookup[1][13]	= 34;
		arrLookup[1][14]	= 32;
		arrLookup[1][15]	= 27;
							
		arrLookup[2][0]		= 42;
		arrLookup[2][1]		= 41;
		arrLookup[2][2]		= 33;
		arrLookup[2][3]		= 48;
		arrLookup[2][4]		= 41;
		arrLookup[2][5]		= 34;
		arrLookup[2][6]		= 32;
		arrLookup[2][7]		= 48;
		arrLookup[2][8]		= 45;
		arrLookup[2][9]		= 17;
		arrLookup[2][10]	= 31;
		arrLookup[2][11]	= 42;
		arrLookup[2][12]	= 36;
		arrLookup[2][13]	= 53;
		arrLookup[2][14]	= 45;
		arrLookup[2][15]	= 48;
							
		arrLookup[3][0]		= 34;
		arrLookup[3][1]		= 48;
		arrLookup[3][2]		= 38;
		arrLookup[3][3]		= 31;
		arrLookup[3][4]		= 45;
		arrLookup[3][5]		= 51;
		arrLookup[3][6]		= 42;
		arrLookup[3][7]		= 60;
		arrLookup[3][8]		= 44;
		arrLookup[3][9]		= 42;
		arrLookup[3][10]	= 38;
		arrLookup[3][11]	= 14;
		arrLookup[3][12]	= 28;
		arrLookup[3][13]	= 13;
		arrLookup[3][14]	= 26;
		arrLookup[3][15]	= 34;
							
		arrLookup[4][0]		= 15;
		arrLookup[4][1]		= 33;
		arrLookup[4][2]		= 25;
		arrLookup[4][3]		= 36;
		arrLookup[4][4]		= 32;
		arrLookup[4][5]		= 28;
		arrLookup[4][6]		= 26;
		arrLookup[4][7]		= 36;
		arrLookup[4][8]		= 36;
		arrLookup[4][9]		= 15;
		arrLookup[4][10]	= 27;
		arrLookup[4][11]	= 33;
		arrLookup[4][12]	= 27;
		arrLookup[4][13]	= 42;
		arrLookup[4][14]	= 36;
		arrLookup[4][15]	= 35;
							
		arrLookup[5][0]		= 25;
		arrLookup[5][1]		= 35;
		arrLookup[5][2]		= 30;
		arrLookup[5][3]		= 24;
		arrLookup[5][4]		= 36;
		arrLookup[5][5]		= 40;
		arrLookup[5][6]		= 33;
		arrLookup[5][7]		= 47;
		arrLookup[5][8]		= 35;
		arrLookup[5][9]		= 33;
		arrLookup[5][10]	= 31;
		arrLookup[5][11]	= 46;
		arrLookup[5][12]	= 13;
		arrLookup[5][13]	= 46;
		arrLookup[5][14]	= 28;
		arrLookup[5][15]	= 38;

		this->LookupTable = new int*[6];

		for(int i = 0; i < m_nNumRows; i++)
		{
			LookupTable[i] = nullptr;
			LookupTable[i] = new int[16];
		}

		for(int x = 0; x < m_nNumRows; x++)
			for(int y = 0; y < m_nNumCols; y++)
				LookupTable[x][y] = arrLookup[x][y];
	}
}